package com.campsys.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.campsys.entity.Teacher;
import com.campsys.entity.User;
import com.campsys.mapper.TeacherMapper;
import com.campsys.mapper.UserMapper;
import com.campsys.service.TeacherService;
import com.campsys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Resource
    private TeacherMapper teacherMapper;
    @Resource
    private UserMapper userMapper;
    @Override
    public List<Teacher> getTeachers() {
        return teacherMapper.getTeachers();
    }

    @Override
    public boolean createTeacher(Teacher teacher) {
        User user = new User();
        user.setLoginName(teacher.getTeacherName());
        user.setPassword("123456");
        user.setUserIdentity("2");
        userMapper.insertUser(user);
        teacher.setLoginId(user.getId());
        return save(teacher)?true:false;
    }

}
